<?php
namespace Admin\Controller;

use Think\Controller;

// 商品分类
class ProductClassController extends Controller
{
	//新增数据
	public function add()
	{
		$this->display();
	}

	public function insert()
	{
		$active = M('Product_class');
			$active->create();
		$result = $active->add();
		if ($result) {
			$this->success('添加成功', 'view');
		} else {
			$this->error('添加失败');
		}
	}

	//用表格的方式显示数据
	public function view()
	{
		$data = M('Product_class'); //实例化Product对象
		// 查询满足要求的总记录数
		$count = $data->count();
		// 实例化分页类 传入总记录数和每页显示的记录数
		$Page = new \Think\Page($count, 20);
		
		$show = $Page->show(); //分页显示输出
		// 进行分页数据查询 注意limit方法的参数要使用Page类的属性
		$list = $data->order('cid')->limit($Page->firstRow.','.$Page->listRows)->select();
		
		$this->assign('list', $list); //赋值数据集				
		$this->assign('page', $show); //赋值分页输出 		
		$this->display(); //输出模板
	}

	//修改数据
	public function save()
	{
		$cid = $_GET['cid'];
		$active = M('Product_class');
		$article = $active->find($cid);
		$this->assign('article',$article);
		$this->display();
	}

	public function amend()
	{
		$active = M('Product_class');    	
	    	$active->create();
		$result = $active->save();
		if ($result) {
			$this->success('修改成功', 'view');
		} else {
			$this->error('修改失败');
		}
	}

	
	//删除数据
	public function cancel()
	{
		$cid = $_GET['cid'];
		$action = M('Product_class');
		$result = $action->where('cid="'.$cid.'"')->delete();
		if ($result) {
			$this->success('删除失败');
		} else {
			$this->error('删除成功', 'view');
		}
	}

}
